package com.sunny.example.string;

import java.util.*;

public class HJ45_名字的漂亮度 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int strings = Integer.parseInt(scanner.nextLine());
            String[] strs = new String[strings];
            for (int k = 0; k < strings; k++) {
                strs[k] = scanner.nextLine().toUpperCase(Locale.ROOT);
            }
            for (String str : strs) {
                String chars = getChars(str);
                //分配漂亮值
                setBeauty(chars, str);
            }

        }
    }

    private static void setBeauty(String chars, String input) {
        int[] s = new int[128];//统计字母ASCII次数
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            s[c]++;
        }

        //排序
        Arrays.sort(s);

        //计算漂亮值
        int maxBeauty = 26;
        int result = 0;
        for (int i = s.length - 1; i >= 0 && s[i] > 0; i--) {
            result += s[i] * maxBeauty;
            maxBeauty--;
        }

        System.out.println(result);

    }

    /**
     * 字符串中字符去重
     *
     * @param str
     */
    private static String getChars(String str) {
        if (null == str || "".equals(str)) {
            return "";
        }
        String tmp = new String();
        for (char c : str.toCharArray()) {
            if (!tmp.contains(String.valueOf(c)))
                tmp += String.valueOf(c);
        }
        return tmp;
    }
}
